package com.meitianhui.convenitenbuy.module.store.presenter;

import com.google.gson.Gson;
import com.meitianhui.convenitenbuy.App;
import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.http.ResponseObserver;
import com.meitianhui.convenitenbuy.module.store.contract.GroupSaleContract;
import com.meitianhui.convenitenbuy.module.store.http.StoreApiDataSource;
import com.meitianhui.convenitenbuy.module.store.model.GroupSaleInfo;
import com.meitianhui.convenitenbuy.module.store.ui.activity.GroupSaleActivity;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by Administrator on 2017/11/27.
 */

public class GroupSalePresenter implements GroupSaleContract.Presenter {

    private GroupSaleActivity mContext;
    private final GroupSaleContract.View mView;

    public GroupSalePresenter(GroupSaleContract.View view, GroupSaleActivity context) {
        this.mView = view;
        this.mContext = context;
    }

    @Override
    public void attachView(Object view) {
    }

    @Override
    public void detachView() {
    }

    @Override
    public void getGroupSale(String storeId) {
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("member_id", storeId);
        hashMap.put("status", "activing");
        String paramJson = new Gson().toJson(hashMap);

        StoreApiDataSource.getInstance()
                .getGroupSale(InfoProvider.getAppToken(App.getInstance()),
                        "order.psGroupGoodsListFind", paramJson)
                .subscribe(new ResponseObserver<BaseResponse<GroupSaleInfo>>(mContext, true) {
                    @Override
                    public void onSuccess(BaseResponse<GroupSaleInfo> response) {
                        mView.getGroupSaleSuccess(response.data);
                    }
                });
    }

}
